import '@/styles/index.scss' // global css
import 'vxe-table/lib/style.css'

import Vue from 'vue'
import App from '@/App.vue'
import router from '@/router'
import store from '@/store'
import i18n from './i18n'

// 引入插件
import '@/icons'
import plugin from '@/plugins'
import * as R from 'ramda'
import ElementUI from 'element-ui'
import VueCookie from 'vue-cookie'
import 'xe-utils'
import VXETable from 'vxe-table'
import VueTableSearchSelect from './components/vueTableSearchSelect.vue'
import splitPane from 'vue-splitpane'

// 加载VabIcon

// 全局引用
window.R = R
Vue.prototype.R = R

Vue.use(R)
Vue.use(plugin)
Vue.use(ElementUI)
Vue.use(VueCookie)
Vue.use(VXETable)
Vue.prototype.$bus = new Vue();

Vue.config.productionTip = false
/*
Vue.component('VabIcon', VabIcon)
*/

Vue.component('split-pane', splitPane)
Vue.component(VueTableSearchSelect.name, VueTableSearchSelect)

VXETable.renderer.add('xVueBoxSearch', {
  autofocus: '.vxe-input--inner',
  renderEdit(h, renderOpts, params) {
    const {row, column} = params
    const options = R.pathOr(() => [], ['editRender', 'optionsGet'], column)()
    const selectedChanged = (item) => {
      row[column.property] = item.value
    }
    return [
      //  // 监听输入事件/
      <vue-table-search-select params={params} selectedChanged={selectedChanged} options={options}  />
    ]
  },

  renderCell(h, renderOpts, {row, column}) {
    const options = R.pathOr(() => [], ['editRender', 'optionsGet'], column)()
    const value = row[column.property]
    const label = R.propOr(value, 'label', R.find(R.propEq('value', value), options))

    return [
      <span>{label}</span>
    ]
  }
})
Vue.prototype.$scrollTo = (x = 0, y = 0, type = 'smooth') => {
  window.scrollTo({
    top: x,
    left: y,
    behavior: type // 滚动行为：smooth平滑滚动，instant瞬间滚动，默认值auto，等同于instant
  })
}


Vue.directive('preventReClick', {
  inserted(el, binding) {
    el.addEventListener('click', () => {
      if (!el.disabled) {
        el.disabled = true;
        setTimeout(() => {
          el.disabled = false;
        }, binding.value || 2000);
      }
    });
  }
});

Vue.directive('removeAriaHidden', {
  bind(el, binding) {
    const ariaEls = el.querySelectorAll('.el-radio__original')
    ariaEls.forEach((item) => {
      item.removeAttribute('aria-hidden')
    })
  }
})

new Vue({
  router,
  i18n,
  store,
  plugin,
  render: h => h(App)
}).$mount('#app')
